package com.example.study.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @Author 宋伟宁
 * @Date 2023/10/8
 * @Version 1.0
 **/
@PropertySource("classpath:jdbc.properties")
public class JdbcConfig {

    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;
    @Value("${jdbc.driver}")
    private String driver;
    @Value("${jdbc.url}")
    private String url;

    @Bean//<bean id="" class="">
    public DataSource dataSource(){
        com.alibaba.druid.pool.DruidDataSource ds=new DruidDataSource();
        ds.setUrl(this.url);
        ds.setDriverClassName(this.driver);
        ds.setUsername(this.username);
        ds.setPassword(this.password);
        return ds;
    }
}
